﻿Imports VB = Microsoft.VisualBasic
Imports Microsoft.Win32
'
Public Class Proxy
    '
    Public Sub New()
        '
    End Sub
    '
    Private Shared _instancia As New Proxy
    '
    Public Shared ReadOnly Property Instancia() As Proxy
        Get
            Return _instancia
        End Get
    End Property
    '
    Private Structure ESTRUCTURA_ENTIDADES_INFO
        Public dwAccessType As Integer
        Public proxy As IntPtr
        Public proxyBypass As IntPtr
    End Structure
    '
    Private Declare Auto Function InternetSetOption Lib "wininet.dll" (ByVal hInternet As IntPtr, ByVal dwOption As Integer, ByVal lpBuffer As IntPtr, ByVal lpdwBufferLength As Integer) As Boolean
    '
    Private Sub ENTIDADES_CONFIGURACION(ByVal strProxy As String)
        Const INTERNET_OPTION_PROXY As Integer = 38
        Const INTERNET_OPEN_TYPE_PROXY As Integer = 3
        Dim s_IPI As ESTRUCTURA_ENTIDADES_INFO
        '
        s_IPI.dwAccessType = INTERNET_OPEN_TYPE_PROXY
        s_IPI.proxy = System.Runtime.InteropServices.Marshal.StringToHGlobalAnsi(strProxy)
        s_IPI.proxyBypass = System.Runtime.InteropServices.Marshal.StringToHGlobalAnsi("Global")
        '
        Dim intptrStruct As IntPtr = System.Runtime.InteropServices.Marshal.AllocCoTaskMem(System.Runtime.InteropServices.Marshal.SizeOf(s_IPI))
        System.Runtime.InteropServices.Marshal.StructureToPtr(s_IPI, intptrStruct, True)
        InternetSetOption(IntPtr.Zero, INTERNET_OPTION_PROXY, intptrStruct, System.Runtime.InteropServices.Marshal.SizeOf(s_IPI))
        '
    End Sub
    '
    Public Sub CONFIGURAR(ByVal Direccion As String)
        '
        ENTIDADES_CONFIGURACION(Direccion)
        '
    End Sub
    '
End Class